﻿using UnityEngine;
using System.Collections;

public partial class PoliceFSM : FriendFSM
{
    void OnEnable()
    {
        gameObject.GetComponent<UnitStatus>().m_unitData.m_CurrentUnitState = BASEUNIT_STATE.IDLE;

        StartCoroutine(InitState());
    }

    IEnumerator InitState()
    {
        gameObject.GetComponent<UnitStatus>().m_unitData.m_CurrentUnitState = BASEUNIT_STATE.IDLE;
        gameObject.transform.GetChild(0).GetChild(0).GetComponent<UnitHeadState>().SetHeadAnim();

        yield return null;

        SetState(gameObject.GetComponent<UnitStatus>().m_unitData.m_CurrentUnitState);
    }


    void SetState(BASEUNIT_STATE iStateKey)
    {

        switch (iStateKey)
        {
            case BASEUNIT_STATE.IDLE:
                StartCoroutine(IdleState());
                break;
            case BASEUNIT_STATE.MOVE:
                StartCoroutine(MoveState());
                break;
            case BASEUNIT_STATE.COVER:
                StartCoroutine(CoverState());
                break;
            case BASEUNIT_STATE.CLOSEATTACK:
                StartCoroutine(CloseAtkState());
                break;
            case BASEUNIT_STATE.AIM:
                StartCoroutine(AImState());
                break;
            case BASEUNIT_STATE.RELOAD:
                StartCoroutine(ReloadState());
                break;
            case BASEUNIT_STATE.DAMAGE:
                StartCoroutine(DamageState());
                break;
            case BASEUNIT_STATE.DEAD:
                StartCoroutine(DeadState());
                break;
            case BASEUNIT_STATE.SUPPLY:
                StartCoroutine(SupplyState());
                break;

            default:
                Debug.Log((int)iStateKey);
                Debug.Log("StateKey Error");
                StartCoroutine(IdleState());
                break;
        }

    }
}
